<!DOCTYPE html>
<html>

	<head>
		<meta charset="UTF-8">
		<title>产品修改页面</title>
		<script type="text/javascript" src="../../js/jquery-3.2.1.js"></script>
		<script type="text/javascript" src="../../js/bootstrap.js"></script>
		<link rel="stylesheet" href="../../css/bootstrap.css" />
		<script type="text/javascript" src="../../js/common.js"></script>
		<script type="text/javascript" src="../../js/product.js"></script>
		<link rel="stylesheet" href="../../css/common.css" />
	</head>

	<body>
		<!-- 这是修改页面,默认隐藏 -->
		<div class="modal fade" id="product-update-modal">
			<div class="modal-dialog">
				<div class="modal-content">
					<form class="form-horizontal" role="form">
						<div class="form-group" style="margin-top: 20px;">
							<label for="inputEmail3" class="col-sm-2 control-label">所属公司</label>
							<div class="col-sm-7">
								<select id="companyId" class="selectpicker show-tick form-control">

								</select>
								<input type="hidden" id="update-hidden" />
							</div>
						</div>
						<div class="form-group" style="margin-top: 20px;">
							<label for="inputEmail3" class="col-sm-2 control-label">产品价格</label>
							<div class="col-sm-7">
								<input type="text" name="productPrice" class="form-control" placeholder="产品价格" />
							</div>
						</div>
						<div class="form-group" style="margin-top: 20px;">
							<label for="inputEmail3" class="col-sm-2 control-label">产品重量</label>
							<div class="col-sm-7">
								<input type="text" name="productWeight" class="form-control" placeholder="产品重量" />
							</div>
						</div>
						<div class="form-group" style="margin-top: 20px;">
							<label for="inputEmail3" class="col-sm-2 control-label">产品名称</label>
							<div class="col-sm-7">
								<input type="text" name="productName" class="form-control" placeholder="产品名称" />
							</div>
						</div>
						<div class="modal-footer">
							<button type="button" class="btn btn-default" data-dismiss="modal" id="colse">关闭</button>
							<button type="button" class="btn btn-primary" id="product-update">保存</button>
						</div>
					</form>
				</div>
			</div>
		</div>

		<!-- 这是失败的页面，默认隐藏 -->
		<div class="modal fade" id="error" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">
			<div class="alert alert-danger alert-dismissable" id="error-message">
			</div>
		</div>

		<!-- 这是成功的页面，默认隐藏 -->
		<div class="modal fade" id="success" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">
			<div class="alert alert-success alert-dismissable" id="success-message">

			</div>
		</div>
	</body>
	<script>
		
		//填充修改方法开始
		$(function(){
			$('#product-update-modal').modal('show');
			var id = getParameter('id');
			$.ajax({
				type:"post",
				url: getPath() + "/product",
				data:({
					"method":"findById",
					"id":id,
				}),
				dataType: "json",
				success:function(jsonData){
					$(jsonData.data).each(function(index,data){
						
						//1.下啦框默认选中开始
						var optionList = $('#companyId option');
						optionList.each(function(index,value){
							if(value.value == data.companyId){
								value.selected = true;
							}
						});
						//1.下啦框默认选中结束
						
						//2.其他input赋值开始
						$('#update-hidden').val(id);
						$('input[name="productPrice"]').val(data.productPrice);
						$('input[name="productWeight"]').val(data.productWeight);
						$('input[name="productName"]').val(data.productName);
						//2.其他input赋值结束
					});
				}
			});
		});
		//填充修改方法结束
	</script>
</html>